#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2510;

int n, m;
struct node
{
	int x, y;
}a[N], b[N];

bool cmp(node& n1, node& n2)
{
	return n1.x > n2.x;
}

int main()
{
	cin >> n >> m;
	for(int i = 1;i <= n;i ++) cin >> a[i].x >> a[i].y;
	for(int i = 1;i <= m;i ++) cin >> b[i].x >> b[i].y;
	// 奶牛按左端点降序,防晒霜按阳光强度降序
	sort(a + 1, a + 1 + n, cmp);
	sort(b + 1, b + 1 + m, cmp);

	int ans = 0;
	for(int i = 1;i <= n;i ++)
	{
		for(int j = 1;j <= m;j ++)
		{
			int t = b[j].x, &cnt = b[j].y;
			if(cnt == 0) continue;
			if(t > a[i].y) continue;
			if(t < a[i].x) break;
			ans ++;
			cnt --;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}